package com.puzzlebazar.client.puzzle.model;

public class MoveGroup extends MoveList {

	/**
	 * 
	 */
	private static final long serialVersionUID = 6296326565896777173L;

	/**
	 * Only for serialization
	 */
	protected MoveGroup() {
		super();
	}
	
	public MoveGroup(long time) {
		super(time);
	}
	
	/**
	 * Adds a move to the list
	 * 
	 * @param move Move to add
	 */
	public void addMove(Move move) {
		if( move instanceof MoveGroup )
			super.append( move );
		else
			super.addMove( move );
	}

	/**
	 * Access the moves in this group
	 * 
	 * @param index Index of move to access
	 * @return The move at the passed index
	 */
	public Move getMove(int index) {
		return moves.get(index);
	}

	/**
	 * Access the number of moves in this group
	 * 
	 * @return The total number of moves in this group
	 */
	public int getMoveCount() {
		return moves.size();
	}
	
	/**
	 * Check if this move group contains any message
	 * 
	 * @return True if the move group contains a message move
	 */
	public boolean containMoveMessage() {
		for (Move move : moves) {
			if( move instanceof MoveMessage )
				return true;
		}
		return false;
	}

	@Override
	public Move apply(PuzzleModel model) throws Exception {
		MoveGroup moveList = new MoveGroup(time);
		return applyDirect(model, moveList);
	}

	@Override
	public Move unapply(PuzzleModel model) throws Exception {
		MoveGroup moveList = new MoveGroup(time);
		return applyReverse(model, moveList);
	}
}
